package com.zhaoc.web.action;

import com.opensymphony.xwork2.ActionContext;
import com.zhaoc.domain.system.Role;
import com.zhaoc.service.IRoleService;
import com.zhaoc.web.base.BaseAction;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>title:com.zhaoc.web.action</p>
 * date:2018/8/22 0022
 * time:21:48
 * author:赵成
 * user:13566
 */
@ParentPackage("json-default")
public class RoleAction extends BaseAction<Role> {

    @Autowired
    private IRoleService roleService;

    @Action(value = "role_list",results = {@Result(name = SUCCESS,type = "json")})
    public String list(){
        List<Role> roles = roleService.findAll();

        ActionContext.getContext().getValueStack().push(roles);
        return SUCCESS;
    }

    private String[] permisssionTd;

    private String menuIds;

    public void setPermisssionTd(String[] permisssionTd) {
        this.permisssionTd = permisssionTd;
    }

    public void setMenuIds(String menuIds) {
        this.menuIds = menuIds;
    }

    @Action(value = "role_save",results = {@Result(name = SUCCESS,type = "redirect",location = "pages/system/role.html")})
    public String save(){
        //调用业务层保存
        roleService.save(model,permisssionTd,menuIds);
        return SUCCESS;
    }
}
